package com.kalvan.core.security;

import org.apache.commons.lang3.RandomStringUtils;

import java.util.Scanner;

/**
 * 密码生成工具类
 *
 * @author chenliang
 */
public class PasswordUtil {

    /**
     * 生成加强密码存储
     *
     * @param password 密码
     * @param salt     盐值
     * @return 加密后的结果
     */
    public static String createSaltPwd(String password, String salt) {
        return MD5.md5(password + salt);
    }

    public static void main(String[] args) {
        System.out.println(createSaltPwd("21232F297A57A5A743894A0E4A801FC3", "2d451a8668b0c5a5df745979e7d2c1ff"));

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入前端明文md5大写密码：");
        String pwd = scan.next();
        String salt = RandomStringUtils.randomAlphabetic(12);

        String password = PasswordUtil.createSaltPwd(MD5.md5(pwd).toUpperCase(), salt);
        System.out.println("生成信息");
        System.out.println("密码盐: " + salt);
        System.out.println("加密密码: " + password);
    }
}
